package com.china08.yxyapi.api.manage.tec.teaching.scoreport.lequestionanalysis;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.entity.mg.scoreport.Exam;
import com.china08.yxyapi.entity.mg.scoreport.Exam.BookContent;
import com.china08.yxyapi.entity.mg.scoreport.report.ExamQuesAnalyse;
import com.china08.yxyapi.model.YxyApiReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.mg.scoreport.ExamQuesAnalyseRepsository;

@CrossOrigin
@RestController
public class LeQuestionAddController {
	@Autowired
	private ExamQuesAnalyseRepsository examQuesAnalyseRepsository;
	@RequestMapping(value = "/api_yw/manage/tec/teaching/scoreport/lequestionanalysis/add/one", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public RespModel precess(HttpServletRequest request, HttpServletResponse response,@RequestBody ReqModel reqModel){
		ExamQuesAnalyse examQuesAnalyse = examQuesAnalyseRepsository.findById(reqModel.quesId);
		List<Exam.BookContent> bookContent = examQuesAnalyse.getExam().getBookContents();
		RespModel model = new RespModel();
		
		BookContent bookContent1=null;
		List<BookContent> bookContentLst = new ArrayList<BookContent>();
		for (Exam.BookContent bookContent2 : bookContent) {
			bookContent1 = new BookContent();
			bookContent1.id = bookContent2.id;
			bookContent1.name = bookContent2.name;
			bookContent1.pId = bookContent2.pid;
			bookContentLst.add(bookContent1);
		}
		model.bookContent = bookContentLst;
		model.semersterName = examQuesAnalyse.getExam().getSemesterName();
        return model;
    }

    protected static class RespModel extends YxyApiRespModel {
    	//章节id、章节父级id、章节name
    	public List<BookContent> bookContent;
    	//策别名称
    	public String semersterName;
    }
    protected static class ReqModel extends YxyApiReqModel {
    	//试题id
    	public String quesId;
    }
    protected class BookContent{
    	public String id;
    	public String name;
    	public String pId;
    }
}
